package es.ibm.santillana.mdm.comments;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.ibm.pim.context.Context;
import com.ibm.pim.context.PIMContextFactory;
import com.ibm.pim.search.SearchQuery;
import com.ibm.pim.search.SearchResultSet;

import es.ibm.santillana.mdm.common.util.PIMDBConnection;

public class CommentsTableLibrary {

	private static String tablename = "comments_item";
	

	
	
	public CommentsTableLibrary() throws IOException, SQLException {
		
	}
	
	
	
	public static boolean existeComentario (PIMDBConnection dbCon, String sItem, String sDate) throws IOException, SQLException {
		
		if (dbCon == null) {
			dbCon = new PIMDBConnection();
		}
		
		String sQuery = "SELECT * FROM " + tablename + " WHERE item = '" + sItem + "' AND date = '" + sDate + "'";
		ResultSet rs = dbCon.executeQuery(sQuery);
		
		return  rs.next();
		
		
		
	}

	
	public static boolean insertaComentario (PIMDBConnection dbCon, String sItem, String sDate, String sComment, String sUser, String sColArea, String sStep ) throws IOException, SQLException {
		
		if (dbCon == null) {
			dbCon = new PIMDBConnection();
		}
		
		String sUpdate = "INSERT INTO " + tablename + "(item,comment,user,colarea,step,date) VALUES ('" + sItem + "','" + sComment + "','" + sUser +"','" + sColArea + "','" + sStep + "','" + sDate + "')";
		System.out.println(sUpdate);
		Integer numRows = dbCon.executeUpdate(sUpdate);
		
		if (numRows!= null){ 
			return  numRows>0;
		}else{
			return false;
		}
		
		
		
	}
	
	
	
	
}
